package com.assistant.activity;

import android.app.Activity;
import android.os.Bundle;

import com.assistant.R;
import com.assistant.adapter.ListAdpter;
import com.assistant.view.CustomListView;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Handler;

public class LoanListActivity extends Activity implements CustomListView.LoadLisener {
    com.assistant.view.CustomListView listView;
    ListAdpter loanAdpter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loan_list);
        listView = (CustomListView) findViewById(R.id.loan_list);
        //listView.setOnScrollListener();
        showListView(getData(5));

    }

    private List<Map<String,Object>> getData(int num){
        List<Map<String,Object>> listItems = new ArrayList<>();
        for (int i =0; i<num; i++ ) {
            Map<String,Object> listItem = new HashMap<>();
            listItem.put("user_logo","http://img4.duitang.com/uploads/item/201502/15/20150215224242_Z5mBC.thumb.224_0.jpeg");
            listItem.put("user_name","测试"+i);
            listItem.put("send_time","09:54");
            listItem.put("msg","你好"+i);
            listItems.add(listItem);
        }
        return listItems;
    }

    @Override
    public void onLoad() {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                showListView(getData(5));
                listView.loadComplete();
            }
        },2000);
    }



    void showListView(List<Map<String,Object>> list) {
        if (loanAdpter == null) {
            listView = (CustomListView) findViewById(R.id.loan_list);
            listView.setLoadLisener(this);
            loanAdpter = new ListAdpter(this,list);
            listView.setAdapter(loanAdpter);
        } else {
            loanAdpter.onDataChange(list);
        }
    }
}
